package cate.game.common.merge;

import cate.game.GameBody;
import cp.solution.business.game.conf.MergeLogEntity;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

@Slf4j
public class MergeTool {

    @FunctionalInterface
    public interface HHH {
        void h(List<MergeLogEntity> logs);
    }

    public static void handle(GameBody game, HHH runnable) {
        List<MergeLogEntity> logs = new ArrayList<>();
        List<MergeLogEntity> mergeLogList = game.process.configFromConsole.progressBootstrap.getMergeLogList();
        if(mergeLogList != null) {
            for(MergeLogEntity ml : mergeLogList) {
                if(!ml.isMarkDone() && ml.getMergeInto()==game.config.srvId) {
                    logs.add(ml);
                }
            }
        }
        if(!logs.isEmpty()) {
            try {
                runnable.h(logs);
            } catch (Exception e) {
                log.error("", e);
            }
        }
    }

}
